package demo.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import demo.model.User;
import demo.service.DemoService;

@Controller
public class DemoController {
	@Autowired
	private DemoService demoService;

	@RequestMapping("/demo/login.do")
	public ModelAndView login(HttpServletRequest request, HttpServletResponse response, String userName, User user) throws Exception {
		System.out.println(user.getPassword());
		String password = request.getParameter("password");
		System.out.println(password);
		User userInfo = demoService.getUserInfo(userName);
		//demoService.saveUserInfo(userName,password);
		if(userInfo == null || "".equals(userInfo)){
			return new ModelAndView("demo/none_user_name","error","What is your input user name:" + userName + ",does not exsits!"); 
		}
		return new ModelAndView("demo/user_info","info",userInfo);
	}
}
